﻿using SketchUpAPI.NET.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.SketchUp
{
    public static class UnitsConverter
    {
        /// <summary>
        /// 进制大小，既 数据 * BaseSize = 英寸
        /// </summary>
        /// <remarks>SketchUp 
        /// 保存数据的单位是英寸，默认转换是从毫米转换为英寸
        /// </remarks>
        public static double BaseSize { get; set; } = 1 / 25.4;

        /// <summary>
        /// 设置默认数据单位
        /// </summary>
        /// <param name="dataUnits"></param>
        public static void SetBaseSize(UnitLengthType dataUnits)
        {
            switch (dataUnits)
            {
                case UnitLengthType.Inches:
                    BaseSize = 1;
                    break;
                case UnitLengthType.Feet:
                    BaseSize = 12;
                    break;
                case UnitLengthType.Millimeters:
                    BaseSize = 1 / 25.4;
                    break;
                case UnitLengthType.Centimeters:
                    BaseSize = 1 / 2.54;
                    break;
                case UnitLengthType.Meters:
                    BaseSize = 1 / 0.0254;
                    break;
                default:
                    BaseSize = 1;
                    break;
            }
        }

        /// <summary>
        /// 转换为模型单位
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double ToModel(this double value) => value * BaseSize;

        /// <summary>
        /// 转换为模型单位
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double ToModel(this int value) => value * BaseSize;

        /// <summary>
        /// 从模型单位转换为自定义单位
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double FromModel(this double value) => value * BaseSize;

        /// <summary>
        /// 米转英寸
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double MetersToInches(this double value) => value / 0.0254;

        /// <summary>
        /// 厘米转英寸
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double CentimetersToInches(this double value) => value / 2.54;

        /// <summary>
        /// 毫米转英寸
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double MillimetersToInches(this double value) => value / 25.4;

        /// <summary>
        /// 英尺转英寸
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double FeetToInches(this double value) => value * 12;

        /// <summary>
        /// 英寸转米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double InchesToMeters(this double value) => value * 0.0254;

        /// <summary>
        /// 英寸转厘米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double InchesToCentimeters(this double value) => value * 2.54;

        /// <summary>
        /// 英寸转毫米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double InchesToMillimeters(this double value) => value * 25.4;

        /// <summary>
        /// 英寸转英尺
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double InchesToFeet(this double value) => value / 12;
    }
}